package com.tobby.camel.camelinaction.chapter4.bean;

import static org.junit.Assert.*;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class SimpleRegistryTest {

	private CamelContext context;

	private ProducerTemplate producerTemplate;

	@Before
	public void setUp() throws Exception {
		// SimpleRegistry registry = new SimpleRegistry();
		// registry.put("helloBean", new HelloBean());

		// context = new DefaultCamelContext(registry);
		context = new DefaultCamelContext();
		producerTemplate = context.createProducerTemplate();
		context.addRoutes(new RouteBuilder() {

			@Override
			public void configure() throws Exception {
				// from("direct:helloBean").bean("helloBean", "hello");
				from("direct:helloBean").bean(HelloBean.class);
			}
		});
		context.start();
	}

	@Test
	public void testHello() {
		Object reply = producerTemplate.requestBody("direct:helloBean",
				"Camel in Action");
		assertEquals("Hello Camel in Action", reply);
	}

	@After
	public void tearDown() throws Exception {
		producerTemplate.stop();
		context.stop();
	}

}
